package com.kangye.learnteacher.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kangye.learnteacher.entity.Classes;
import com.kangye.learnteacher.entity.Grade;
import com.kangye.learnteacher.entity.Subject;
import com.kangye.learnteacher.entity.TypePaper;
import com.kangye.learnteacher.mapper.CorrectionMapper;
import com.kangye.learnteacher.service.CorrectionService;
import com.kangye.learnteacher.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @program: learndeduo
 * @description: 批改试卷业务层实现类
 * @author: 李豪杰
 * @create: 2021-05-17 15:17
 **/
@Service
public class CorrectionServiceImpl implements CorrectionService {

    @Autowired
    private CorrectionMapper correctionMapper;

    /**
     * 查询学科
     * @param SubjectId
     * @return
     */
    @Override
    public List<Subject> getSubjectId(Integer SubjectId) {
        return correctionMapper.getSubjectId(SubjectId);
    }

    /**
     * 查询班级
     * @param classesId
     * @return
     */
    @Override
    public List<Classes> getClasses(Integer classesId) {
        return correctionMapper.getClasses(classesId);
    }

    /**
     * 查询试卷列表
     * @param page
     * @param limit
     * @param classesId
     * @param subjectId
     * @return
     */
    @Override
    public ViewJsonObject<Map<String, Object>> getStudentParper(Integer page, Integer limit, Integer classesId, Integer subjectId,Integer gradeId,Integer spCorrectStatus) {
        ViewJsonObject<Map<String, Object>> viewJsonObject = new ViewJsonObject<>();
        PageHelper.startPage(page,limit);
        //查询未批改试卷
        List<Map<String, Object>> list = correctionMapper.getStudentParper(gradeId,classesId,subjectId,spCorrectStatus);

        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        viewJsonObject.setData(pageInfo.getList());
        viewJsonObject.setCount(pageInfo.getTotal());
        viewJsonObject.setCode(0);
        viewJsonObject.setMsg("");
        return viewJsonObject;
    }


    /**
     * 查询年级
     * @return
     */
    @Override
    public List<Grade> getGrade() {
        return correctionMapper.getGrade();
    }

    /**
     * 获取需要批改的试卷
     * @param spId
     * @return
     */
    @Override
    public List<Map<String, Object>> getPaper(Integer spId,Integer spCorrectStatus) {
        return correctionMapper.getPaper(spId,spCorrectStatus);
    }

    @Override
    public Integer shenpi(Integer score,Integer spid) {
        return correctionMapper.shenpi(score,spid);
    }
}
